# coding:utf-8
# 作者：理想国真恵玩
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data = pd.read_csv("data/stock.csv")
# 寻找星期几跟股票张得的关系
# 1、先把对应的日期找到星期几
date = pd.to_datetime(data.index).weekday
data['week'] = date

# 2、假如把p_change按照大小去分个类0为界限
data['posi_neg'] = np.where(data['p_change'] > 0, 1, 0)

# 通过交叉表找寻两列数据的关系
count = pd.crosstab(data['week'], data['posi_neg'])

# 算数运算，先求和
sum = count.sum(axis=1).astype(np.float32)

# 进行相除操作，得出比例
pro = count.div(sum, axis=0)

pro.plot(kind='bar', stacked=True)
plt.show()
